<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH.'models/model_crud.php');
require_once(APPPATH.'models/model_kontak.php');

class Model_grup extends Model_crud {

	private $id;

	private $nama;

	private $keterangan;

	public static $tabel = 'pbk_groups';

	public function __construct($data) {
		$this->id 	= $data->grup_id;
		$this->nama = $data->nama;
		$this->keterangan = $data->keterangan;
	}

	public static function read($filter = array(), $limit=array()) {
		$hasil = parent::read($filter, $limit);

		if ($hasil!==false){
			$objek = array();
			
			foreach ($hasil as $grup)
				$objek[$grup->grup_id] = new model_grup($grup);

			return $objek;
		}
		else
			return false;
	}

	public static function read_anggota($array_grup) {

		model_crud::$tabel = 'pbk';
		model_crud::$tabel_join = array('pbk_relasi'=>'pbk.pbk_id = pbk_relasi.pbk_id');

		$anggota_grup = model_crud::read(array('grup_id'=> $array_grup), array(), 'pbk.*', true);
		
		$objek = array();
		foreach ($anggota_grup as $anggota)
			$objek[] = new model_kontak($anggota);

		return $objek;
	}

	public function get_id(){
		return $this->id;
	}

	public function get_nama(){
		return $this->nama;
	}

	public function get_keterangan(){
		return $this->keterangan;
	}

}